#include "Model/OneOccurenceRule.hpp"
#include "CalendarRuleTests.hpp"
#include <boost/test/auto_unit_test.hpp>

namespace
{

using namespace Model;

BOOST_AUTO_TEST_CASE( testNoIntersection)
{
	OneOccurenceRule rule;
	Calendar::Time 
		iStart( Calendar::Date( 2008, 12, 22)), 
		iEnd( Calendar::Date( 2008, 12, 24));
	rule.setInterval( iStart, iEnd);

	Calendar::Time 
		rStart( Calendar::Date( 2008, 12, 20)),
		rEnd( Calendar::Date( 2008, 12, 26));
	Calendar::PeriodSet result;
	rule.getPeriods( rStart, rEnd, result);

	BOOST_REQUIRE_EQUAL( 1, result.size());
	CHECK_TIME_INTERVAL( iStart, iEnd, *result.begin());
}

// ---------------------------------------------------------------------------------------------------------------------

BOOST_AUTO_TEST_CASE( testWithIntersection)
{
	OneOccurenceRule rule;
	Calendar::Time 
		iStart( Calendar::Date( 2008, 12, 20)), 
		iEnd( Calendar::Date( 2008, 12, 26));
	rule.setInterval( iStart, iEnd);

	Calendar::Time 
		rStart( Calendar::Date( 2008, 12, 22)),
		rEnd( Calendar::Date( 2008, 12, 24));
	Calendar::PeriodSet result;
	rule.getPeriods( rStart, rEnd, result);

	BOOST_REQUIRE_EQUAL( 1, result.size());
	CHECK_TIME_INTERVAL( rStart, rEnd, *result.begin());
}

} // namespace
